home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / 3DGPL 1.0 / CODE / HARDWARE / Macintosh / HARDWARE.c next >
Encoding:
C/C++ Source or Header  |  1997-04-19  |  3.6 KB  |  132 lines  |  [TEXT/CWIE]

  1. /** 3DGPL *************************************************\
  2.  *  (Macintosh, 8bit deep bitmaps, 32bit machine)          *     
  3.  *  Header for hardware specific stuff.                   *
  4.  *                                                        *
  5.  *  hardware.c               hardware specific stuff.     *
  6.  *                                                        *
  7.  *  (6/1995) By Sergei Savhenko. (savs@cs.mcgill.ca).     *
  8.  *  Copyright (c) 1995 Sergei Savchenko.                  *
  9.  *  THIS SOURCE CODE CAN'T BE USED FOR COMERCIAL PURPOSES *
  10.  *  WITHOUT AUTHORISATION                                 *
  11. \**********************************************************/
  12. // Mac version hacked by Ingemar 1997
  13.  
  14. #include "hardware.h"                         /* memset etc. */
  15.  
  16. #include <QDOffScreen.h>
  17. #include <Palettes.h>
  18.  
  19. static WindowPtr wind;
  20. static GWorldPtr offscreenGWorld;
  21.  
  22. /**********************************************************\
  23.  *  Implementations for fast memory operations.           *
  24. \**********************************************************/
  25.                   
  26. void HW_set_int(int *d,long l,int v) {long i; for(i=0;i<l;i++) *d++=v; }
  27.  
  28. //void HW_set_int(int *dst,long lng,int val)
  29. //{
  30. //}
  31.  
  32. #define rLeft 40
  33. #define rTop 40
  34.  
  35.  
  36. int HW_open_screen(char *display_name,
  37.                    char *screen_name, 
  38.                    struct HW_colour palette[256],
  39.                    unsigned char *colourmap
  40.                   )
  41. {
  42.     Rect    boundsRect;
  43.     OSErr    myErr;
  44.     CTabHandle    theCTab;
  45.     int        i;
  46.  
  47.     InitGraf (&qd.thePort);
  48.     InitFonts ();
  49.     InitWindows ();
  50.     InitMenus ();
  51.     TEInit ();
  52.     InitDialogs (nil);
  53.     InitCursor ();
  54.     
  55.     SetRect(&boundsRect,rLeft,rTop,rLeft+HW_SCREEN_X_SIZE,rTop+HW_SCREEN_Y_SIZE);
  56.     wind = NewCWindow(nil,&boundsRect,"\p",true,plainDBox,(WindowPtr)-1,false,0);
  57.     SetPort(wind);
  58.  
  59. // Set the palette to the one passed from 3DGPL
  60.     theCTab = (CTabHandle)NewHandle(8 + 256 * 8); //8 bytes header + 8 bytes per colour}
  61.     (**theCTab).ctSize = 255;
  62.     (**theCTab).ctFlags = 0;
  63.     for(i=0;i<256;i++)
  64.     {
  65.         (**theCTab).ctTable[i].value = i;
  66.         (**theCTab).ctTable[i].rgb.red = palette[i].hw_r << 8;
  67.         (**theCTab).ctTable[i].rgb.green = palette[i].hw_g << 8;
  68.         (**theCTab).ctTable[i].rgb.blue = palette[i].hw_b << 8;
  69.     }
  70.     (**theCTab).ctSeed = GetCTSeed();
  71.     SetEntries(0, 255, (**theCTab).ctTable);
  72.     DisposeHandle((Handle)theCTab);
  73.  
  74. // Create offscreen GWorld
  75.     OffsetRect(&boundsRect, -boundsRect.left, -boundsRect.top);
  76.     myErr = NewGWorld(&offscreenGWorld,8,&boundsRect,nil,nil,0);
  77.     LockPixels(offscreenGWorld->portPixMap);
  78.  
  79. // Use the base address passed from 3DGPL.
  80. // BUG: Doesn't dispose the old data
  81.     (**offscreenGWorld->portPixMap).baseAddr = (char *)colourmap;
  82.     (**offscreenGWorld->portPixMap).rowBytes = 0x8000 | HW_SCREEN_X_SIZE;
  83. }
  84.  
  85. void HW_blit(void)
  86. {
  87.     CGrafPtr    savePort;
  88.     GDHandle    saveDev;
  89.     
  90.     CopyBits(    &((GrafPtr)(offscreenGWorld))->portBits,
  91.                 &((GrafPtr)(wind))->portBits,
  92.                 &offscreenGWorld->portRect,
  93.                 &wind->portRect,
  94.                 srcCopy,nil);
  95.     GetGWorld(&savePort, &saveDev);
  96.     SetGWorld(offscreenGWorld, nil);
  97.     PaintRect(&offscreenGWorld->portRect);
  98.     SetGWorld(savePort, saveDev);
  99. }
  100.  
  101. void HW_close_screen(void)
  102. {
  103. // Put back the palette
  104.     RestoreDeviceClut(nil);
  105.     DisposeWindow(wind);
  106. }
  107.  
  108. static Boolean done;
  109.  
  110. void HW_run_event_loop(void (*application_main)(void),
  111.                        void (*application_key_handler)(int key_code)
  112.                       )
  113. {
  114.     EventRecord theEvent;
  115.     
  116.     done = false;
  117.  
  118.  while(!Button() && !done) // Temporary solution - set "done" with cmd-Q and/or click in close box instead
  119.  {
  120.     if(GetOSEvent(keyDownMask+autoKeyMask,&theEvent))
  121.     {
  122.        application_key_handler(theEvent.message & charCodeMask);
  123.     }
  124.   application_main();
  125.  }
  126. }
  127.  
  128. void HW_quit_event_loop(void)
  129. {
  130.     done = true;
  131. }
  132.